from django.db import models
from django import forms
from django.forms import ModelForm
from ocms.eventmanager.models import *
from django.contrib.auth.models import *

def getForm(eventtype, *args, **kwargs):
    '''
    Name:         getForm (eventtype, *args, **kwargs)
    Arguments:     eventtype = string event type
                *args = generic arg array  (for passthrough)
                **kwargs = generic keyword arg array (for passthrough)
    Return:        ModelForm
    Purpose: This is a generic function that will take in event type (and optional arguments for Form Generation functions) and return a form of the appropriate event type.
    '''
    form=None
    if (eventtype=="training event"):
        form = TrainingEventForm(*args, **kwargs)
    elif (eventtype=="promotional event"):
        form = PromotionalEventForm(*args, **kwargs)
    elif (eventtype=="partner event"):
        form = PartnerEventForm(*args, **kwargs)
    elif (eventtype=="local event"):
        form = LocalEventForm(*args, **kwargs)
    elif (eventtype=="regional event"):
        form = RegionalEventForm(*args, **kwargs)
    elif (eventtype=="global app sec event"):
        form = GlobalAppSecEventForm(*args, **kwargs)
    return form


class UserFullnameChoiceField(forms.SelectMultiple):
    def label_from_instance(self, obj):
        return smart_unicode(obj.get_full_name())
                                         
class EventForm(ModelForm):
    def __init__(self, *args, **kwargs):
        super(EventForm, self).__init__(*args, **kwargs)

        #this overwrites the names of the planning teams in the form to real user names
        users = User.objects.all().exclude(id=1).order_by('last_name', 'first_name')
        self.fields['planning_team'].choices = [(user.pk, user.get_full_name()) for user in users]

    class Meta:
         model = Event
         #planning_team = UserFullnameChoiceField()
         exclude = ('approval_status','event_status','gcc_rep', 'intro_keynote', 'owasp_particpation', 'reg_link')
         widgets = {
                'Start_Date': widgets.AdminDateWidget(),
                'End_Date': widgets.AdminDateWidget(),
                
                }
         
class PromotionalEventForm(EventForm):
     class Meta(EventForm.Meta):
         model = PromotionalEvent
         
class PartnerEventForm(EventForm):
     class Meta(EventForm.Meta):
         model = PartnerEvent
         
class TrainingEventForm(EventForm):
     class Meta(EventForm.Meta):
         model = TrainingEvent
         
class LocalEventForm(EventForm):
     class Meta(EventForm.Meta):
         model = LocalEvent
         
class RegionalEventForm(EventForm):
     class Meta(EventForm.Meta):
         model = RegionalEvent

class GlobalAppSecEventForm(EventForm):
     class Meta(EventForm.Meta):
         model = GlobalAppSecEvent
         
